package com.zy.sjlk.service.impl;

import com.zy.common.constant.CityConstant;
import com.zy.iservice.domain.IntfaceReverseHistory;
import com.zy.reverse.service.IReverseIntService;
import com.zy.sjlk.service.ISjlkTestService;
import com.zy.tsk.service.ITskService;
import com.zy.utils.TskSqlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * TskServiceImpl
 *
 * @author javachen
 */
@Service
public class SjlkTestServiceImpl implements ISjlkTestService
{

    private final String tableName = "SPT_TEST";

    @Autowired
    public ITskService tskService;

    @Autowired
    private IReverseIntService reverseIntService;

    @Override
    public void loadData() {

        tskService.delete(TskSqlUtils.getClearOtherDay(tableName));

        //1.将医疗监管总费用落入数据库中

        Map<String, Integer> cityMap = CityConstant.CITY_MAP;

        IntfaceReverseHistory intfaceReverseHistory = new IntfaceReverseHistory();
        intfaceReverseHistory.setType(3L);
        intfaceReverseHistory.setReverseUserName("admin");
        intfaceReverseHistory.setReverseUserId(1L);

        for (String cityName : cityMap.keySet()) {
            String cityCode = cityMap.get(cityName) + "";
            Map<String, Object> map = new HashMap<>();
            map.put("cityCode", cityCode);
            Map<String, Object> resultMap = (Map<String, Object>) reverseIntService.reverseInt("yljg", "findZfy", map,intfaceReverseHistory);
            if(null!=resultMap&&resultMap.size()>0){
                executeDeleteAndInsert(tableName, cityCode, cityName, "医疗监管", "总费用", resultMap.get("VALUE") + "");
            }
        }

    }

    public void executeDeleteAndInsert(String tableName, String cityCode, String cityName, String dpType, String name, String value) {
        tskService.delete(TskSqlUtils.getDelete(tableName, cityCode, dpType, name));
        tskService.insert(TskSqlUtils.getInsert(tableName, cityCode, cityName, dpType, name, value));
    }
}
